<?php 
	// 验证用户是否登录
	require_once 'session-check.php';
	
	$user = $_SESSION['login_user'];
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>站点管理-管理文章</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link rel="stylesheet" type="text/css" href="../style/admin.css"/>
	</head>
	<body>
	<div class="head">
		站点后台管理  [<a href=".." style="font-color:white">返回站点</a>]
	</div>
	<div class="userinfo">
		当前登录用户:
		<?php 
			echo $user;
			echo ' [<a href="user-action.php?action=logout">注销登陆</a>]';
			echo ' [<a href="user-admin.php">修改密码</a>]';
		?>
	</div>
	<div class="container">
		<div class="left">
			<h1>功能列表</h1>
			<ul>	
				<li><a href="user-admin.php">管理用户</a></li>
				<li>管理文章</li>
				<li><a href="feedback-admin.php">管理评论</a></li>
			</ul>
		</div>
		<div class="right">
		<?php
			require_once '../util/dbconnection.php';
			connect_db();
			$about_list = get_titles_by_category( "about" , 1);
			$know_list = get_titles_by_category( "knowledge" , 1);
			$trash_lit = get_titles_by_category( "", 2 );   // 已删除评论
			close_db();
		
			echo "<h1>管理文章--分类列表</h1>";
			// 文章列表
			echo "<ul>";
			echo '<li><a href="post-add-edit.php?action=add">添加新文章</a></li>';
			echo "<li>公司介绍</li>";
			echo_post_list($about_list, 1);
			echo "<li>花卉知识</li>";
			echo_post_list($know_list, 1);
			echo "<li>垃圾箱</li>";
			echo_post_list($trash_lit, 2);
			echo "</ul>";
			
			function echo_post_list($list, $type){
				echo '<table border="1px" cellspacing="0" cellpadding="5px">';
				if( count($list) == 0 ){
					echo "<tr><td>没有删除的文章</td></tr>";
					return;
				}
				$index = 1;
				echo '<tr><td>序号</td><td>标题</td><td>分类</td><td>发表日期</td><td>最后修改日期</td><td colspan=2>操作</td></tr>';
				foreach( $list as $key => $value ){
				  	echo '<tr>';
				  	echo "<td>$index</td>";
				  	echo '<td>'.$value['title'].'</td>';
				  	echo '<td>'.$value['category'].'</td>';
				  	echo '<td>'.$value['post_date'].'</td>';
				  	echo '<td>'.$value['modify_date'].'</td>';
				  	if( $type == 1  ){
					  	echo '<td><a href="post-add-edit.php?action=edit&id='.$key.'">编辑</a></td>';
					  	echo '<td><a href="post-action.php?action=del&id='.$key.'">删除</a></td>';
				  	}else if( $type == 2 ){
				  		echo '<td><a href="post-action.php?action=restore&id='.$key.'">恢复</a></td>';
				  		echo '<td><a href="post-action.php?action=destroy&id='.$key.'">彻底删除</a></td>';
				  	}
					echo '</tr>';
					$index++;
				}
				echo "</table>";
			}
		?>
		</div>
	</div>	
	</body>
</html>
